import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    name:"Login",
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/chooseRegister',
    name:"ChooseRegister",
    component: () => import('@/views/login/chooseRegister'),
    hidden: true
  },
  {
    path: '/nRegister',
    name:"NRegister",
    component: () => import('@/views/login/normalRegister'),
    hidden: true
  },
  {
    path: '/bRegister',
    name:"BRegister",
    component: () => import('@/views/login/businessRegister'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'logo' }
    }]
  },
  {
    path: '/orderProcess1',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'orderProcess1',
      name: 'OrderProcess1',
      hidden: true,
      component: () => import('@/views/normalUsers/orderProcess1'),
      meta: { title: '提交订单', icon: '123' }
    }],
  },
  {
    path: '/orderProcess2',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'orderProcess2',
      name: 'OrderProcess2',
      hidden: true,
      component: () => import('@/views/normalUsers/orderProcess2'),
      meta: { title: '确认支付', icon: '123' }
    }],
  },
  {
    path: '/orderProcess3',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'orderProcess3',
      name: 'OrderProcess3',
      hidden: true,
      component: () => import('@/views/normalUsers/orderProcess3'),
      meta: { title: '完成支付', icon: '123' }
    }],
  },
  {
    path: '/goods',
    component: Layout,
    redirect:'',
    name:'Goods',
    meta:{title:'商品',icon:'el-icon-s-help'},
    children:[
      {
        path: 'goodsDetails',
        name: 'GoodsDetails',
        component: () => import('@/views/goods/goodsDetails'),
        meta: { title: '商品详情', icon: 'el-icon-present' }
      },
      {
        path: 'goodsDetails',
        name: 'GoodsDetails',
        component: () => import('@/views/goods/goodsDetails'),
        meta: { title: '$%^&*(', icon: 'el-icon-present' }
      }
    ]
  },

  {
    path: '/normal',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '普通用户后台', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'myInfo',
        name: 'MyInfo',
        component: () => import('@/views/normalUsers/myinfo'),
        meta: { title: '我的个人信息', icon: 'people' }
      },
      {
        path: 'myOrder',
        name: 'MyOredr',
        component: () => import('@/views/normalUsers/myOrder'),
        meta: { title: '我的订单', icon: 'list' }
      },
      {
        path: 'myCollect',
        name: 'MyCollect',
        component: () => import('@/views/normalUsers/myCollects'),
        meta: { title: '我的收藏', icon: 'star' }
      },
      {
        path: 'myMessage',
        name: 'MyMessage',
        hidden: true,
        component: () => import('@/views/tree/index'),
        meta: { title: '我的通知', icon: 'message' }
      },
      {
        path: 'writeTravelNote',
        name: 'writeTravelNote',
        component: () => import('@/views/travelnotes/writeTravelNote'),
        meta: { title: '写游记', icon: 'message' }
      },
      {
        path: 'readTravelNote',
        name: 'readTravelNote',
        hidden: true,
        component: () => import('@/views/travelnotes/readTravelNote'),
        meta: { title: '读游记', icon: 'message' }
      },
      {
        path: 'findAllScenic',
        name: 'findAllScenic',
        component: () => import('@/views/scenic/findAllScenic'),
        meta: { title: '旅游攻略', icon: 'message' }
      },
      {
        path: 'scenicDetails',
        name: 'scenicDetails',
        hidden: true,
        component: () => import('@/views/scenic/scenicDetails'),
        meta: { title: '攻略详情', icon: 'message' }
      }
    ]
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    meta: { title: '商家用户后台', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'goods',
        name: 'Goods',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '商品管理', icon: 'list' },
        children:[
          {
            path: 'goodsList',
            name: 'GoodsList',
            component: () => import('@/views/dashboard/index'),
            meta: { title: '商品列表'},
          },{
            path: 'addGoods',
            name: 'AddGoods',
            component: () => import('@/views/dashboard/index'),
            meta: { title: '商品上架'},
          },
          {
            path: 'goodsComment',
            name: 'GoodsComment',
            component: () => import('@/views/dashboard/index'),
            meta: { title: '商品评论'},
          }
        ]
      },
      /* {
        path: 'order',
        name: 'Order',
        component: () => import('@/views/order/order'),
        meta: { title: '订单管理', icon: 'shopping' }
      }, */
      {
        path: 'turnover',
        name: 'Turnover',
        component: () => import('@/views/table/index'),
        meta: { title: '营业额管理', icon: 'money' },
        children:[
          {
            path: 'amountCheck',
            name: 'AmountCheck',
            component: () => import('@/views/dashboard/index'),
            meta: { title: '对账统计', icon: 'money' },
          },
          {
            path: 'withdrawal',
            name: 'Withdrawal',
            component: () => import('@/views/dashboard/index'),
            meta: { title: '提现', icon: 'money' },
          }
        ]
      },
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: '管理员后台',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'managerGoods',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'ManagerGoods',
        meta: { title: '商品管理',icon:"list" },
        children: [
          {
            path: 'managerGoodsList',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'ManagerGoodsList',
            meta: { title: '普通商品列表' }
          },
          {
            path: 'managerKillGoodsList',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'ManagerKillGoodsList',
            meta: { title: '秒杀商品列表' },
          },
        ]
      },
      {
        path: 'managerOrder',
        component: () => import('@/views/order/order'), // Parent router-view
        name: 'managerOrder',
        meta: { title: '订单管理',icon:"list" },
      },
      {
        path: 'addScenic',
        component: () => import('@/views/scenic/addScenic'), // Parent router-view
        name: 'addScenic',
        meta: { title: '新增景点',icon:"list" },
      },
      {
        path: 'updateScenic',
        component: () => import('@/views/scenic/updateScenic'), // Parent router-view
        name: 'updateScenic',
        hidden: true,
        meta: { title: '编辑景点',icon:"list" },
      },
      {
        path: 'managerScenic',
        component: () => import('@/views/scenic/managerScenic'), // Parent router-view
        name: 'managerScenic',
        meta: { title: '景点管理',icon:"list" },
      },
      {
        path: 'normalUsers',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'NormalUsers',
        meta: { title: '普通用户管理',icon:"peoples" },
        children: [
          {
            path: 'normalUsersList',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'NormalUsersList',
            meta: { title: '普通用户列表' ,icon:"peoples" }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
        ]
      },
      {
        path: 'businesslUsers',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'BusinessUsers',
        meta: { title: '商铺用户管理',icon:"peoples" },
        children: [
          {
            path: 'businessUsersList',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'BusinessUsersList',
            meta: { title: '商铺用户列表' ,icon:"peoples" }
          },
          {
            path: 'checkBusinessUser',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'CheckBusinessUser',
            meta: { title: '商铺用户审核',icon:"peoples" },
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
